<?php
$loader->requireOnce('includes/CorePayment/BillImporter.abstract.php');
$loader->requireOnce('includes/CorePayment/ServiceFeeItem.class.php');
class OutServiceImporter extends BillImporter {
	private $itemList =   array();

    public function readData() {
        $ticketId     =   $this->storage->getTicketId();
        $serviceType  =   EnumerationConstant::PAYMENT_ITEM_TYPE_SERVICE_KEY;
        
        // Get pay_payment_item records of 'service' type
        $sql    =   "SELECT ppi.pay_payment_item_id, ppi.service_id, ppi.service_name, ppi.unit, ppi.quantity,
                        ppi.unit_price, pis.price as insurance_remuneration, pis.enum_group_type
                FROM pay_payment_item ppi
                    INNER JOIN pay_payment pp ON (pp.pay_payment_id  = ppi.pay_payment_id
                        AND pp.ticket_id='$ticketId' AND ppi.enum_item_type = '$serviceType')
                    LEFT JOIN service s ON (ppi.service_id = s.service_id)
                    LEFT JOIN pay_insurance_support pis ON (s.pay_insurance_support_id = pis.pay_insurance_support_id)";
        $res    =   $this->db->execute($sql);
        while ($res && !$res->EOF) {
        	$billableItem  =   new ServiceFeeItem($res->fields['service_id'], $res->fields['service_name'], $res->fields['unit'],
        	   $res->fields['quantity'], $res->fields['unit_price'], $res->fields['unit_price'], $res->fields['unit_price'],
               $res->fields['enum_group_type'], $res->fields['insurance_remuneration']);
            $billableItem->setItemId($res->fields['pay_payment_item_id']);
            $this->storage->addItem(PaymentConstant::ITEM_SERVICE, $billableItem);
        	$res->moveNext();
        }
    }

    public function updateBillStorage(){
        
    }
}
?>